<%@ page import="java.util.jar.Attributes.Name"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="support.*, java.util.*" %>
    
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Degree-Location</title>
<link href="main.css" rel="stylesheet" type="text/css">
</head>
<body>

<%
	// Get address from HTTP request
	if (session.getAttribute("address")==null)
	{
		String street = request.getParameter("street");
		String city = request.getParameter("city");
		String state = request.getParameter("state");
		if (state==null) state = "";
		String zipcode = request.getParameter("zipcode");
		String countrycode = request.getParameter("countrycode");
		if (countrycode==null) countrycode = "";
		String areacode = request.getParameter("areacode");
		String phone = request.getParameter("phone");
		
		// Store address in session
		Map address = new HashMap();
		address.put("street", street);
		address.put("city", city);
		address.put("state", state);
		address.put("zipcode", zipcode);
		address.put("countrycode", countrycode);
		address.put("areacode", areacode);
		address.put("phone", phone);
		session.setAttribute("address", address);
	}

	// Get countries from text file
	support s = new support();
	
	Vector universities = (Vector) application.getAttribute("universities");
	if(universities == null)
	{
		String path = config.getServletContext().getRealPath("universities.txt");
		universities = s.getUniversities(path);
		application.setAttribute("universities", universities);
	}
%>

<h1>Provide degrees - Choose location</h1>
	<table class="multicolumn">
		<tr>
			<% 
			int cols = 3;
			int itemsPerCol = universities.size() / cols;
			if (universities.size() % cols != 0) itemsPerCol += 1;
			for(int i=0; i<universities.size(); i++){
				if (i % itemsPerCol == 0)  out.println("<td style=\"vertical-align:top\">");
				String location = (String)((Vector) universities.get(i)).get(0);
				out.println("<a href=\"university.jsp?location_id=" + i +  "\">" + location + "</a><br />");
				if (i % itemsPerCol == itemsPerCol-1 || i==universities.size() -1 )  out.println("</td>");
			};
			%>
		</tr>
	</table>
	<form name="form1" action="university.jsp" method="get">
		<h1>If not found, input your degree location below:</h1><br>
		<input type="text" name="location" value="">
		<input type="submit" value = "submit">
	</form>	
</body>
</html>